#pragma once

#include "public/build.h"
#include "core/noncopy.h"

#include "client/iconsole.h"

#include <Windows.h>
#include <vector>
#include <string>

namespace renderit
{
	namespace client
	{
		class console : public iconsole
		{
		public:
			console(const std::string& name);
			virtual ~console() {}

		public:
			/*
			 * tell current position
			 */
			virtual math::coord curr_pos() const override;

			/*
			 * set cursor
			 */
			virtual bool set_curr_pos(const math::coord& pos) override;

			/*
			 * write to current position
			 */
			virtual iconsole * write(const std::string& content) override;

			/*
			 * write to current position
			 */
			virtual iconsole * write(const char * fmt, ...) override;

			/*
			 * clear current line
			 */
			virtual void clear_line() override;

			/*
			 * back to last line and clear
			 */
			virtual void back_line() override;

		public:
			/*
			* do input
			*
			*/
			void do_input();


		private:
			/*
			* peek input without removing it from the buffer
			*/
			int peek_input();

			int get_inputs_count() const { return cached_inputs_.size(); }
			std::vector<std::string> get_inputs() { std::vector<std::string> r = std::move(cached_inputs_); return r; }

		private:
			std::string name_;

			std::string curr_input_;
			std::vector<std::string> cached_inputs_;

			HANDLE houtput_;
			HANDLE hinput_;
		};
	}
}